package cn.xaut.剑指offer.m10;

import cn.xaut.剑指offer.m01.ListNode;

/**
 * 剑指 Offer 18. 删除链表的节点
 */
public class demo18 {

    public ListNode deleteNode(ListNode head, int val) {

        if (head.val == val)    // 也不知道为啥没有这一句就不能ac
            return head.next;
        
        ListNode prev = new ListNode(-1, head);
        while (prev.next != null) {
            if (prev.next.val == val) {
                prev.next = prev.next.next;
                break;
            } else 
                prev = prev.next;
        }
        return head;
    }
}
